<template>
  <div class="container"  v-if="list.length">
    <div v-for="(item, index) in list" :key="index" class="notice-cell" @click="toOrderList(item)">
      <div v-if="item.is_read" class="dot"></div>
      <div class="content" >
        {{item.title ? item.title : '暂无标题'}}: &nbsp;&nbsp;&nbsp;{{ item.center ? item.center : '暂无内容' }}
      </div>
      <div class="time">
        {{ item.created_at }}
      </div>
    </div>
    <load-more @loadMore="loadMore"></load-more>
  </div>
</template>

<script>
import loadMore from "@/components/load-more";
import { getOrderMsg } from "@/api/msg-center";
export default {
  data() {
    return {
      list: [],
      page: 1,
      loading: false,
      isAll: false
    };
  },
  methods: {
    toOrderList(item) {
      this.$router.push( {path: '/order-detail', query: {order_no: item.order_no, status: item.status}})
    },
    loadMore() {
      if (this.loading || this.isAll || this.list.length === 0) return;
      this.loading = true;
      this.getOrderMsg(++this.page);
    },
    getOrderMsg(page) {
      getOrderMsg({ page }).then(res => {
        console.log(res)
        if (res.status === 200) {
          this.list.push(...res.data.data.list);
          if (res.data.data.length === 0) {
            this.isAll = true;
            this.$dialog.toast({
              mes: "已经到最底了",
              timeout: 1500
            });
          }
        }
        this.$nextTick(() => {
          this.loading = false;
        });
      });
    }
  },
  created() {
    this.getOrderMsg(1);
  },
  components: {
    loadMore
  }
};
</script>

<style lang="less" scoped>
.container {
  min-height: 100%;
  height: auto;
  padding-bottom: 1rem;
  .notice-cell {
    margin: 0.48rem 3.2% 0;
    background: #fff;
    // height: 2rem;
    line-height: 1rem;
    padding-top: 0.4rem;
    padding-bottom: 0.4rem;
    padding-left: 0.88rem;
    position: relative;
    padding-right: 3.2%;
    display: flex;
    justify-content: space-between;

    .dot {
      height: 0.4rem;
      width: 0.4rem;
      background-color: #f85859;
      border-radius: 50%;
      border: 0.04rem solid rgba(255, 255, 255, 1);
      position: absolute;
      left: 2.2%;
      top: calc(50% - 0.2rem);
    }

    .content {
      font-size: 0.56rem;
      color: #444444;
      max-width: 75%;
      overflow: hidden;
    }

    .time {
      font-size: 0.44rem;
      color: #999999;
    }
  }
}
</style>
